﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using RSHTreelReset;

namespace RSHTrealReset
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                var rshassembly = "JetBrains.Platform.ReSharper.Shell.dll";
                if(args.Length == 1)
                {
                    rshassembly = args[0];
                }

                if (!File.Exists(rshassembly))
                {
                    Console.WriteLine("Assembly {0} not found. Try specified path from command line like 'c:\\Program Files (x86)\\JetBrains\\ReSharper\\v6.1\\Bin\\{0}'", rshassembly);
                }

                var assembly = Assembly.LoadFrom(rshassembly);
                var id = (string)assembly.GetType("JetBrains.Application.Defines").GetField("LicenseSupportIdentifier").GetValue(null);

                FreeEvaluationInfo freeTrialInfo = FreeEvaluationInfo.GetFreeTrialInfo(id, FreeEvaluationInfo.ROOT_KEY);
                freeTrialInfo.TrialStart = FreeEvaluationInfo.INSTALLER_TIME;
                FreeEvaluationInfo.SetFreeTrialInfo(id, freeTrialInfo, FreeEvaluationInfo.ROOT_KEY);
                Console.WriteLine("Treal reset");
            }
            catch (Exception ex)
            {
                Console.WriteLine((object)ex);
            }
        }
    }
}
